#ifndef _cping_h_
#define _cping_h_

#if _MSC_VER > 1000
	#pragma once
#endif

#include "npsync.h"
#include "npsock.h"
#include "ILocker.h"

class CPingNoLock
{
public:
	CPingNoLock();
	~CPingNoLock();

	int Ping(DWORD ipAddr, DWORD milliseconds_timeout = 30);
	int Ping(LPCTSTR hostName, DWORD milliseconds_timeout = 30);

private:
	CPingNoLock(const CPingNoLock&);
	CPingNoLock& operator=(const CPingNoLock&);

private:
	SOCKET m_sockfd;
};

class CPing : public CPingNoLock
{
public:
	int Ping(DWORD ipAddr, DWORD milliseconds_timeout = 30)
	{
		CNPAutoLock autoLock(m_lock);
		return CPingNoLock::Ping(ipAddr, milliseconds_timeout);
	}

	int Ping(LPCTSTR hostName, DWORD milliseconds_timeout = 30)
	{
		CNPAutoLock autoLock(m_lock);
		return CPingNoLock::Ping(hostName, milliseconds_timeout);
	}

private:
	CLocker m_lock;
};

inline BOOL Ping(DWORD ip, DWORD milliseconds_timeout = 30)
{
	CPingNoLock ping;
	return 0 == ping.Ping(ip, milliseconds_timeout);
}

inline BOOL Ping(LPCTSTR host, DWORD milliseconds_timeout = 30)
{
	CPingNoLock ping;
	return 0 == ping.Ping(host, milliseconds_timeout);
}

#endif /* _cping_h_ */
